#pragma once
#include "../data/CreditDebtRankingData.h"
#include <bondlib/SSSortInfo.h>
#include <QWidget>
#include <QStylePainter>
#include <vector>

class SVirtualTable;
class DefaultTableModel;
class STableColumnSet;
class CPanListData;
class xQBPanoramicMarketStreamDealAck;
class SCheckComboBox;

class CreditDebtRankingList : public QWidget
{
public:
	CreditDebtRankingList(QWidget* p, CreditDebtRankingData* data);
	void setData(CreditDebtRankingData* data);
	void onReloadData();
protected:
	virtual sortKey getSortKey(int col) = 0;
	virtual void updateTable(bool reset) = 0;
	virtual void loadData();
	virtual void updateTableHeader();
	virtual void updateFlash();
protected slots:
	virtual void onHeaderSort(int col);
	virtual void onTableRowDblClicked(const QModelIndex& index);
protected:
	typedef struct dataInfo {
		int type=CreditDebtRankingData::type_Active;//数据类型
		int count=20;								 //条数
		bool needcount=false;						 //是否条数有效（count是否生效）
	}DataInfo;

	SVirtualTable* m_table;
	STableColumnSet* m_tableSet;
	DefaultTableModel* m_model;
	std::vector<int> m_cols;
	CreditDebtRankingData* m_data;
	std::vector<CNewBondPanDeal> m_lstPDeal;
	DataInfo m_datainfo;
	CSortInfoManager m_sortinfo;
};

//活跃成交
class CreditDebtRankingActiveList : public CreditDebtRankingList {
	enum holidayType{ emHolidayNull = 0, emHolidayCib, emHolidaySSE };
	enum emColActive {
		fuCol_REMAIN = 0, //剩余期限
		fuCol_SHORT,	  //简称
		fuCol_COUNT,	  //成交笔数
		fuCol_ADV,		  //平均成交
		fuCol_YES,		  //昨日成交
		fuCol_HIGH,		  //最高
		fuCol_LOW,		  //最低
		fuCol_MAX
	};
public:
	CreditDebtRankingActiveList(QWidget* p, CreditDebtRankingData* data);
private:
	void initTable();
	sortKey getSortKey(int col) override;
	void updateTable(bool reset) override;
};

//涨跌幅榜
class CreditDebtRankingUpdownList : public CreditDebtRankingList {
	enum emColUpDown {
		//fuCol_REMAIN = 0, //剩余期限
		fuCol_SHORT = 0,	//简称
		fuCol_UP,			//净价偏离
		fuCol_UPBP,			//偏离BP
		//fuCol_COUNT,		//笔数
		//fuCol_LIQUIDITY,	//流动性
		fuCol_MAX
	};
public:
	enum emType {
		emTypeUp = 0, //涨幅榜
		emTypeDown	  //跌幅榜
	};
	CreditDebtRankingUpdownList(QWidget* p, CreditDebtRankingData* data, emType type);
private:
	void initTable();
	sortKey getSortKey(int col) override;
	void updateTable(bool reset) override;
	void setDoubleColor(double val, QColor& cr, QString& strText, bool needPercent, bool reverseColor=false);
private:
	emType m_type;
};

//20日首次成交
class CreditDebtRanking20DaysFirstList : public CreditDebtRankingList {
	enum emColFirst {
		//fuCol_REMAIN = 0, //剩余期限
		fuCol_SHORT = 0,	//简称
		fuCol_PRC,			//价格
		fuCol_COUNT,		//笔数
		fuCol_LIQUIDITY,	//流动性
		fuCol_TIME,			//时间
		fuCol_MAX
	};
public:
	CreditDebtRanking20DaysFirstList(QWidget* p, CreditDebtRankingData* data);
protected slots:
	void onFilterChanged();
private:
	void initTable();
	sortKey getSortKey(int col) override;
	void updateTable(bool reset) override;
	void updateBondPanCondition();
	void setTransactionTime(time_t tmCurrent, time_t tmModify, QString& strText, bool bUseDate);
	SCheckComboBox* getCheckComboBox() const;
};